package com.cq.hd.member.controller;

import com.alibaba.fastjson.JSONObject;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbMemberCardApi;
import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;
import com.cq.hd.member.service.TbMemberCardService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 次卡表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-19
 */
@RestController
public class TbMemberCardController implements TbMemberCardApi {

    @Autowired
    private TbMemberCardService memberCardService;

    @ApiOperation(value = "保存次卡配置")
    @ApiImplicitParam(name = "memberCardSaveDto", value = "保存参数", required = true, paramType = "body", dataType = "MemberCardSaveDto")
    @Override
    public Result<Long> saveMemberCard(@RequestBody MemberCardSaveDto memberCardSaveDto) {
        return ResultGenerator.success(memberCardService.saveMemberCard(memberCardSaveDto));
    }

    @ApiOperation(value = "更新次卡配置")
    @ApiImplicitParam(name = "memberCardUpdateDto", value = "更新参数", required = true, paramType = "body", dataType = "MemberCardUpdateDto")
    @Override
    public Result<Boolean> updateMemberCard(@RequestBody MemberCardUpdateDto memberCardUpdateDto) {
        return ResultGenerator.success(memberCardService.updateMemberCard(memberCardUpdateDto));
    }

    @ApiOperation(value = "次卡配置列表")
    @ApiImplicitParam(name = "memberCardPageDto", value = "商家配置实体", required = true, paramType = "query", dataType = "MemberCardPageDto")
    @ApiResponse(response = MemberCardPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<MemberCardPageVo>> pageMemberCard(MemberCardPageDto memberCardPageDto) {
        return ResultGenerator.success(memberCardService.pageMemberCard(memberCardPageDto));
    }

    @ApiOperation(value = "次卡购买列表")
    @ApiResponse(response = AppMemberCardPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<AppMemberCardPageVo>> pageAppMemberCard(AppMemberCardPageDto appMemberCardPageDto) {
        return ResultGenerator.success(memberCardService.pageAppMemberCard(appMemberCardPageDto));
    }

    @ApiOperation(value = "创建订单，返回充值订单号")
    @ApiImplicitParam(name = "appMemberCardCreateDto", value = "实体", required = true, paramType = "body", dataType = "AppMemberCardCreateDto")
    @Override
    public Result<String> createAppMemberCardOrder(@RequestBody AppMemberCardCreateDto appMemberCardCreateDto) {
        return ResultGenerator.success(memberCardService.createAppMemberCardOrder(appMemberCardCreateDto));
    }

    @ApiOperation(value = "立即支付，唤起第三方支付")
    @ApiImplicitParam(name = "appMemberCardPayDto", value = "实体", paramType = "body", dataType = "AppMemberCardPayDto")
    @ApiResponse(response = AppMemberCardPayVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppMemberCardPayVo> payAppMemberCardOrder(@RequestBody AppMemberCardPayDto appMemberCardPayDto) {
        return ResultGenerator.success(memberCardService.payAppMemberCardOrder(appMemberCardPayDto));
    }

    @ApiOperation(value = "聚合正扫下单回调")
    @Override
    public Result<Boolean> jsPayCallback(@RequestBody JSONObject dataObj) {
        return ResultGenerator.success(memberCardService.jsPayCallback(dataObj));
    }

    @ApiOperation(value = "查单（只要唤醒了第三方支付，关闭第三方支付页面之后，不管是成功还是失败，都要调用）")
    @Override
    public Result<Boolean> queryOrderPay(@RequestBody AppMemberCardPayQueryDto appMemberCardPayQueryDto) {
        return ResultGenerator.success(memberCardService.queryOrderPay(appMemberCardPayQueryDto));
    }

    @ApiOperation(value = "获取次卡详情")
    @Override
    public Result<MemberCardPageVo> detailById(Long id) {
        return ResultGenerator.success(memberCardService.detailById(id));
    }

    @ApiOperation(value = "网银支付购买次卡")
    @Override
    public Result<BankPayRechargeVo> bankPayAppMemberCardOrder(@RequestBody AdminBusinessMemberCardPayDto adminBusinessMemberCardPayDto) {
        return ResultGenerator.success(memberCardService.bankPayAppMemberCardOrder(adminBusinessMemberCardPayDto));
    }

    @ApiOperation(value = "网银支付查单")
    @Override
    public Result<BankPayQueryVo> queryBankPayOrder(@RequestBody BankPayQueryDto bankPayQueryDto) {
        return ResultGenerator.success(memberCardService.queryBankPayOrder(bankPayQueryDto));
    }

    @ApiOperation(value = "网银购买次卡回调")
    @Override
    public Result<Boolean> bankPayCallback(@RequestBody JSONObject dataObj) {
        return ResultGenerator.success(memberCardService.bankPayCallback(dataObj));
    }
}
